<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>【CSS杂谈】全兼容的毛玻璃效果 | Vixcity</title><meta name="keywords" content="CSS"><meta name="author" content="Vixcity"><meta name="copyright" content="Vixcity"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="【CSS杂谈】全兼容的毛玻璃效果通过本文，你能了解到  最基本的使用 CSS backdrop-filter 实现磨砂玻璃(毛玻璃)的效果 在至今不兼容 backdrop-filter 的 firefox 浏览器，如何利用一些技巧性的操作，巧妙的同样实现毛玻璃效果，让这个效果真正能运用在业务当中  什么是 backdrop-filterbackdrop-filter CSS 属性可以让你为一个元素">
<meta property="og:type" content="article">
<meta property="og:title" content="【CSS杂谈】全兼容的毛玻璃效果">
<meta property="og:url" content="http://vixcity.gitee.io/my-gitee-blog/2021/09/13/%E3%80%90CSS%E3%80%91%E5%85%A8%E5%85%BC%E5%AE%B9%E7%9A%84%E6%AF%9B%E7%8E%BB%E7%92%83%E6%95%88%E6%9E%9C/index.html">
<meta property="og:site_name" content="Vixcity">
<meta property="og:description" content="【CSS杂谈】全兼容的毛玻璃效果通过本文，你能了解到  最基本的使用 CSS backdrop-filter 实现磨砂玻璃(毛玻璃)的效果 在至今不兼容 backdrop-filter 的 firefox 浏览器，如何利用一些技巧性的操作，巧妙的同样实现毛玻璃效果，让这个效果真正能运用在业务当中  什么是 backdrop-filterbackdrop-filter CSS 属性可以让你为一个元素">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://vixcity.gitee.io/my-gitee-blog/img/CSS.jpg">
<meta property="article:published_time" content="2021-09-12T16:00:00.000Z">
<meta property="article:modified_time" content="2022-01-04T03:04:47.315Z">
<meta property="article:author" content="Vixcity">
<meta property="article:tag" content="CSS">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://vixcity.gitee.io/my-gitee-blog/img/CSS.jpg"><link rel="shortcut icon" href="/my-gitee-blog/img/favicon.ico"><link rel="canonical" href="http://vixcity.gitee.io/my-gitee-blog/2021/09/13/%E3%80%90CSS%E3%80%91%E5%85%A8%E5%85%BC%E5%AE%B9%E7%9A%84%E6%AF%9B%E7%8E%BB%E7%92%83%E6%95%88%E6%9E%9C/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/my-gitee-blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/my-gitee-blog/',
  algolia: undefined,
  localSearch: {"path":"/my-gitee-blog/search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":1,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: '/my-gitee-blog/',
      css: '/my-gitee-blog/'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '【CSS杂谈】全兼容的毛玻璃效果',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2022-01-04 11:04:47'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/my-gitee-blog/css/mycss.css"><link rel="stylesheet" href="/my-gitee-blog/css/newStyle.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome-animation@1.1.1/css/font-awesome-animation.css"><link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-card-history/baiduhistory/css/main.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.css"><link rel="stylesheet" href="https://unpkg.zhimg.com/hexo-butterfly-wowjs/lib/animate.min.css" media="print" onload="this.media='screen'"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/my-gitee-blog/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/my-gitee-blog/archives/"><div class="headline">文章</div><div class="length-num">55</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/my-gitee-blog/tags/"><div class="headline">标签</div><div class="length-num">50</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/my-gitee-blog/categories/"><div class="headline">分类</div><div class="length-num">18</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/my-gitee-blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/PicBed"><i class="fa-fw fas fa-image"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/my-gitee-blog/img/CSS.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/my-gitee-blog/">Vixcity</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/my-gitee-blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/PicBed"><i class="fa-fw fas fa-image"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/my-gitee-blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">【CSS杂谈】全兼容的毛玻璃效果</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-09-12T16:00:00.000Z" title="发表于 2021-09-13 00:00:00">2021-09-13</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-01-04T03:04:47.315Z" title="更新于 2022-01-04 11:04:47">2022-01-04</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/my-gitee-blog/categories/%E5%A4%A7%E5%89%8D%E7%AB%AF/">大前端</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/my-gitee-blog/categories/%E5%A4%A7%E5%89%8D%E7%AB%AF/CSS/">CSS</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.7k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>10分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="【CSS杂谈】全兼容的毛玻璃效果"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="【CSS杂谈】全兼容的毛玻璃效果"><a href="#【CSS杂谈】全兼容的毛玻璃效果" class="headerlink" title="【CSS杂谈】全兼容的毛玻璃效果"></a>【CSS杂谈】全兼容的毛玻璃效果</h2><p>通过本文，你能了解到</p>
<ol>
<li>最基本的使用 CSS <code>backdrop-filter</code> 实现磨砂玻璃(毛玻璃)的效果</li>
<li>在至今不兼容 <code>backdrop-filter</code> 的 firefox 浏览器，如何利用一些技巧性的操作，巧妙的同样实现毛玻璃效果，让这个效果真正能运用在业务当中</li>
</ol>
<h2 id="什么是-backdrop-filter"><a href="#什么是-backdrop-filter" class="headerlink" title="什么是 backdrop-filter"></a>什么是 <code>backdrop-filter</code></h2><p><code>backdrop-filter</code> CSS 属性可以让你为一个元素后面区域添加图形效果（如模糊或颜色偏移）</p>
<p>因为它适用于元素背后的所有元素，为了看到效果，必须使元素或其背景至少部分透明</p>
<p><code>backdrop-filter</code> 与 <code>filter</code> 非常类似，可以取的值都是一样的</p>
<p>但是一个是作用于整个元素，一个是只作用于元素后面的区域</p>
<h3 id="backdrop-filter-与-filter-对比"><a href="#backdrop-filter-与-filter-对比" class="headerlink" title="backdrop-filter 与 filter 对比"></a><code>backdrop-filter</code> 与 <code>filter</code> 对比</h3><p>我们使用 <code>backdrop-filter</code> 与 <code>filter</code> 同时实现一个毛玻璃效果作为对比，伪代码如下：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;bg&quot;</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>Normal<span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;g-filter&quot;</span>&gt;</span>filter<span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;g-backdrop-filter&quot;</span>&gt;</span>backdrop-filter<span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.bg</span> &#123;  </span><br><span class="line">    <span class="attribute">background</span>: <span class="built_in">url</span>(<span class="string">image.png</span>);  </span><br><span class="line">      </span><br><span class="line">    &amp; &gt; <span class="selector-tag">div</span> &#123;  </span><br><span class="line">        <span class="attribute">width</span>: <span class="number">300px</span>;  </span><br><span class="line">        <span class="attribute">height</span>: <span class="number">200px</span>;  </span><br><span class="line">        <span class="attribute">background</span>: <span class="built_in">rgba</span>(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>, .<span class="number">7</span>);  </span><br><span class="line">    &#125;  </span><br><span class="line">    <span class="selector-class">.g-filter</span> &#123;  </span><br><span class="line">        <span class="attribute">filter</span>: <span class="built_in">blur</span>(<span class="number">6px</span>);  </span><br><span class="line">    &#125;  </span><br><span class="line">    <span class="selector-class">.g-backdrop-filter</span> &#123;  </span><br><span class="line">        backdrop-<span class="attribute">filter</span>: <span class="built_in">blur</span>(<span class="number">6px</span>);  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;  </span><br></pre></td></tr></table></figure>

<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109131432854.webp" alt="CodePen Demo -- filter 与 backdrop-filter 对比"></p>
<p>在 <code>backdrop-filter</code> 之前，想实现上述的只给元素背景添加滤镜效果还是非常困难的</p>
<p>并且，对于静态画面还好，如果背景还是可以滚动的动态背景，通常 CSS 是无能为力的</p>
<p><code>backdrop-filter</code> 正是为了给元素后的内容添加滤镜而不影响元素本身而诞生的</p>
<p>使用它可以非常方便的实现磨砂玻璃效果（毛玻璃）！</p>
<h2 id="backdrop-filter-的兼容性"><a href="#backdrop-filter-的兼容性" class="headerlink" title="backdrop-filter 的兼容性"></a><code>backdrop-filter</code> 的兼容性</h2><p><code>backdrop-filter</code> 其实已经诞生挺久了，然而，firefox 至今都不兼容它！</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109131434027.webp" alt="图片"></p>
<p>对于部分已经放弃了 IE 的 PC 端业务而言，firefox 还是需要兼容的</p>
<p>想要让使用 <code>backdrop-filter</code> 实现毛玻璃效果应用落地，firefox 的兼容问题必须得解决</p>
<h2 id="在-firefox-中实现毛玻璃效果"><a href="#在-firefox-中实现毛玻璃效果" class="headerlink" title="在 firefox 中实现毛玻璃效果"></a>在 firefox 中实现毛玻璃效果</h2><p>OK，本文的重点就是在于如何在 firefox 中，不使用 <code>backdrop-filter</code> 而尽可能的还原毛玻璃的效果</p>
<p>首先看一下，如果是正常使用  <code>backdrop-filter</code>，还是上述的例子效果如下，是没有毛玻璃效果的：</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109131436549.webp" alt="图片"></p>
<h3 id="使用-background-attachment-fixed-兼容静态背景图"><a href="#使用-background-attachment-fixed-兼容静态背景图" class="headerlink" title="使用 background-attachment: fixed 兼容静态背景图"></a>使用 background-attachment: fixed 兼容静态背景图</h3><p>如果在 firefox 上想使用毛玻璃效果</p>
<p>应用毛玻璃元素的背景只是一张静态背景图，其实方法是有很多的</p>
<p>我们只需在元素的背后，叠加一张同样的图片，利用 <code>background-attachment: fixed</code> 将叠加在元素下面的图片定位到与背景相同的坐标，再使用 <code>filter: blur()</code> 对其进行模糊处理即可。</p>
<p>伪代码如下：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;g-glossy&quot;</span>&gt;</span>frosted glass effect <span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br></pre></td></tr></table></figure>

<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">$<span class="selector-tag">img</span>: <span class="string">&#x27;https://static.pexels.com/photos/373934/pexels-photo-373934.jpeg&#x27;</span>;  </span><br><span class="line">  </span><br><span class="line"><span class="selector-tag">body</span> &#123;  </span><br><span class="line">    <span class="attribute">height</span>: <span class="number">100vh</span>;  </span><br><span class="line">    <span class="attribute">display</span>: flex;  </span><br><span class="line">    <span class="attribute">background-image</span>: <span class="built_in">url</span>(<span class="string">$img</span>);  </span><br><span class="line">    <span class="attribute">background-repeat</span>: no-repeat;  </span><br><span class="line">    <span class="attribute">background-attachment</span>: fixed;  </span><br><span class="line">    <span class="attribute">background-size</span>: cover;  </span><br><span class="line">&#125;  </span><br><span class="line">  </span><br><span class="line"><span class="selector-class">.g-glossy</span> &#123;  </span><br><span class="line">    <span class="attribute">position</span>: relative;  </span><br><span class="line">    <span class="attribute">width</span>: <span class="number">600px</span>;  </span><br><span class="line">    <span class="attribute">height</span>: <span class="number">300px</span>;  </span><br><span class="line">    <span class="attribute">background-color</span>: <span class="built_in">rgba</span>(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0.5</span>);  </span><br><span class="line">    <span class="attribute">overflow</span>: hidden;  </span><br><span class="line">    <span class="attribute">z-index</span>: <span class="number">10</span>;  </span><br><span class="line">      </span><br><span class="line">    &amp;<span class="selector-pseudo">::before</span> &#123;  </span><br><span class="line">        <span class="attribute">content</span>: <span class="string">&quot;&quot;</span>;  </span><br><span class="line">        <span class="attribute">position</span>: absolute;  </span><br><span class="line">        <span class="attribute">top</span>: <span class="number">0</span>;  </span><br><span class="line">        <span class="attribute">left</span>: <span class="number">0</span>;  </span><br><span class="line">        <span class="attribute">right</span>: <span class="number">0</span>;  </span><br><span class="line">        <span class="attribute">bottom</span>: <span class="number">0</span>;  </span><br><span class="line">        <span class="attribute">background-image</span>: <span class="built_in">url</span>(<span class="string">$img</span>);  </span><br><span class="line">        <span class="attribute">background-repeat</span>: no-repeat;  </span><br><span class="line">        <span class="attribute">background-attachment</span>: fixed;  </span><br><span class="line">        <span class="attribute">background-size</span>: cover;  </span><br><span class="line">        <span class="attribute">filter</span>: <span class="built_in">blur</span>(<span class="number">10px</span>);  </span><br><span class="line">        <span class="attribute">z-index</span>: -<span class="number">1</span>;  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;  </span><br></pre></td></tr></table></figure>

<p>效果如下：</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109131438150.webp" alt="图片"></p>
<p>此方法也是在没有 <code>backdrop-filter</code> 之前，在各个浏览器想实现简单毛玻璃效果最常用的方法之一</p>
<p>CodePen Demo – 使用 background-attachment: fixed | filter: bulr() 实现毛玻璃效果</p>
<h4 id="使用-background-attachment-fixed-兼容静态背景图的缺点"><a href="#使用-background-attachment-fixed-兼容静态背景图的缺点" class="headerlink" title="使用 background-attachment: fixed 兼容静态背景图的缺点"></a>使用 background-attachment: fixed 兼容静态背景图的缺点</h4><p>不过这种方法也有两个缺点：</p>
<ol>
<li><p>由于使用了伪元素叠加了一层背景，因为层级关系，父元素的 background 是在最下层的，所以元素本身的背景色其实并没有被充分体现，可以对比下两种方法的实际效果图：</p>
<p> <img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109131439762.webp" alt="图片"></p>
<p> 解决方案是再通过另外一个伪元素再叠加一层背景色，这个背景色应该是原本赋值给父元素本身的。</p>
<p> 叠加之后的效果如下：</p>
<p> <img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109131439476.webp" alt="image"></p>
<p> CodePen Demo – 使用 background-attachment: fixed | filter: bulr() 实现毛玻璃效果优化</p>
</li>
<li><p>上述效果已经非常接近了，硬要挑刺的话，就是应用了模糊滤镜的伪元素的边缘有白边瑕疵，这一点其实是滤镜本身的问题，也非常好解决，我们只需要将伪元素的范围扩大一点即可：</p>
</li>
</ol>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.g-glossy</span> &#123;  </span><br><span class="line">    <span class="attribute">overflow</span>: hidden;  </span><br><span class="line">    ....  </span><br><span class="line">    &amp;<span class="selector-pseudo">::before</span> &#123;  </span><br><span class="line">        <span class="attribute">content</span>: <span class="string">&quot;&quot;</span>;  </span><br><span class="line">        <span class="attribute">position</span>: absolute;  </span><br><span class="line">        <span class="attribute">top</span>: -<span class="number">100px</span>;  </span><br><span class="line">        <span class="attribute">left</span>: -<span class="number">100px</span>;  </span><br><span class="line">        <span class="attribute">right</span>: -<span class="number">100px</span>;  </span><br><span class="line">        <span class="attribute">bottom</span>: -<span class="number">100px</span>;  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;  </span><br></pre></td></tr></table></figure>

<p>定位的代码由 <code>top: 0px;</code> 改为 <code>top: -100px</code>，四个方位都是如此即可</p>
<p>如此一来，就能做到基本上是百分百的模拟</p>
<h3 id="使用-moz-element-配合-filter-blur-实现复杂背景毛玻璃效果"><a href="#使用-moz-element-配合-filter-blur-实现复杂背景毛玻璃效果" class="headerlink" title="使用 moz-element() 配合 filter: blur() 实现复杂背景毛玻璃效果"></a>使用 <code>moz-element()</code> 配合 <code>filter: blur()</code> 实现复杂背景毛玻璃效果</h3><p>下面这种方法就非常巧妙了，正常而言，运用毛玻璃效果的背景元素，都不是一张图片那么简单！</p>
<p>背后通常都是整个页面复杂的结构，多层 DOM 的嵌套。</p>
<p>那么通过叠加一张简单的图片，就无法奏效了，我们得想办法模拟整个 DOM 元素。</p>
<p>而恰好，在 Firefox 中，有这么一个属性 – <code>-moz-element()</code>。</p>
<p>何为 <code>-moz-element()</code>？</p>
<p>[MDN-element](<a target="_blank" rel="noopener" href="https://developer.mozilla.org/en-US/docs/Web/CSS/element">https://developer.mozilla.org/en-US/docs/Web/CSS/element</a>( “MDN-element”)) 的解释是:</p>
<blockquote>
<p>CSS 函数 <code>element()</code> 定义了一个从任意的 HTML 元素中生成的图像 <code>&lt;image&gt;</code> 值。该图像值是实时的，这意味着如果被指定的 HTML 元素被更改，应用了该属性的元素的背景也会相应更改。</p>
</blockquote>
<p>它其实是个草案规范，但是一直以来，只有 Firefox 支持它 – CAN I USE – CSS element()：</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109131441736.webp" alt="图片"></p>
<p>它有什么作用呢？</p>
<h3 id="moz-element-如何使用"><a href="#moz-element-如何使用" class="headerlink" title="-moz-element() 如何使用"></a><code>-moz-element()</code> 如何使用</h3><p>那么 <code>-moz-element()</code> 如何使用呢？</p>
<p>简而言之，它能够复制一个元素内部渲染出来的 UI，并且能够实时同步变化。</p>
<p>假设我们有这样一个简单的结构，元素背景和内容都在运动：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;bg&quot;</span> <span class="attr">class</span>=<span class="string">&quot;g-normal&quot;</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span>&gt;</span>Content<span class="tag">&lt;/<span class="name">p</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br></pre></td></tr></table></figure>

<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.g-normal</span> &#123;  </span><br><span class="line">    <span class="attribute">margin</span>: auto;  </span><br><span class="line">    <span class="attribute">width</span>: <span class="number">200px</span>;  </span><br><span class="line">    <span class="attribute">height</span>: <span class="number">200px</span>;  </span><br><span class="line">    <span class="attribute">animation</span>: change <span class="number">5s</span> infinite;  </span><br><span class="line">    <span class="attribute">background</span>: <span class="built_in">linear-gradient</span>(deeppink, yellowgreen);  </span><br><span class="line">&#125;  </span><br><span class="line">  </span><br><span class="line"><span class="selector-tag">p</span> &#123;  </span><br><span class="line">    <span class="attribute">animation</span>: move <span class="number">5s</span> infinite;  </span><br><span class="line">&#125;  </span><br><span class="line">  </span><br><span class="line"><span class="keyword">@keyframes</span> change &#123;  </span><br><span class="line">    <span class="number">0%</span> &#123;  </span><br><span class="line">        <span class="attribute">filter</span>: <span class="built_in">hue-rotate</span>(<span class="number">0</span>);  </span><br><span class="line">    &#125;  </span><br><span class="line">    <span class="number">100%</span> &#123;  </span><br><span class="line">        <span class="attribute">filter</span>: <span class="built_in">hue-rotate</span>(<span class="number">360deg</span>);  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;  </span><br><span class="line">  </span><br><span class="line"><span class="keyword">@keyframes</span> move &#123;  </span><br><span class="line">    <span class="number">0%</span> &#123;  </span><br><span class="line">        <span class="attribute">transform</span>: <span class="built_in">translate</span>(<span class="number">0</span>, <span class="number">0</span>);  </span><br><span class="line">    &#125;  </span><br><span class="line">    <span class="number">100%</span> &#123;  </span><br><span class="line">        <span class="attribute">transform</span>: <span class="built_in">translate</span>(<span class="number">150px</span>, <span class="number">150px</span>);  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;  </span><br></pre></td></tr></table></figure>

<p>它的效果大概是这样：</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109131442195.gif" alt="图片"></p>
<p>我们就假设这个结构就是我们页面某一块的内容，然后，我们就可以使用 <code>background: -moz-element(#id)</code> 这种方式，将这个元素内绘制的 UI 内容完全拷贝至另外一个元素，看看效果。  </p>
<p>我们添加一个元素 <code>&lt;div class=&quot;g-element-copy&quot;&gt;&lt;/div&gt;</code>，在这个元素内模拟 <code>#bg</code> 内的内容：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;bg&quot;</span> <span class="attr">class</span>=<span class="string">&quot;g-normal&quot;</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span>&gt;</span>Content<span class="tag">&lt;/<span class="name">p</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;g-element-copy&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br></pre></td></tr></table></figure>

<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.g-element-copy</span> &#123;  </span><br><span class="line">    <span class="attribute">margin</span>: auto;  </span><br><span class="line">    <span class="attribute">width</span>: <span class="number">200px</span>;  </span><br><span class="line">    <span class="attribute">height</span>: <span class="number">200px</span>;  </span><br><span class="line">    // 核心代码  </span><br><span class="line">    <span class="attribute">background</span>: <span class="built_in">-moz-element</span>(#bg);  </span><br><span class="line">&#125;  </span><br></pre></td></tr></table></figure>

<p>它可以完全复制另外一个元素内绘制出来的 UI，并且能追踪实时变化：</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109131443566.gif" alt="图片"></p>
<p>CodePen Demo – -moz-element Demo(Firefox Only)</p>
<h2 id="在-firefox-中使用-element-复制-UI，用作毛玻璃元素背景"><a href="#在-firefox-中使用-element-复制-UI，用作毛玻璃元素背景" class="headerlink" title="在 firefox 中使用 element 复制 UI，用作毛玻璃元素背景"></a>在 firefox 中使用 element 复制 UI，用作毛玻璃元素背景</h2><p>这样，有了上面的铺垫，下面的内容就比较好理解了</p>
<p>和上述的 <code>background-attachment: fixed</code> 方案对比，我们还是通过伪元素叠加一层背景</p>
<p>只不过背景内的内容由单纯一张图片，变成了由 <code>-moz-element()</code> 复制的整段 UI 内容</p>
<p>其次，上面的方案我们使用 <code>background-attachment: fixed</code> 使背景图和伪元素内叠加的图片的位置对齐</p>
<p>在这里，我们需要借助 Javascript 进行简单的运算，确定背景内容元素的相关位置，计算对齐量</p>
<p>来看这样一个 DEMO：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;bg&quot;</span> <span class="attr">class</span>=<span class="string">&quot;bg&quot;</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>模拟真实 DOM<span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>模拟真实 DOM<span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>模拟真实 DOM<span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>模拟真实 DOM<span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>模拟真实 DOM<span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>模拟真实 DOM<span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>模拟真实 DOM<span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>模拟真实 DOM<span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>模拟真实 DOM<span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;g-glossy&quot;</span>&gt;</span>frosted glass effect <span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;g-glossy-firefox&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span>  </span><br></pre></td></tr></table></figure>

<p>其中，<code>.g-glossy</code> 是在正常情况下 <code>backdrop-filter</code> 兼容时，我们的毛玻璃元素，而 <code>.g-glossy-firefox</code> 则是不兼容 <code>backdrop-filter</code> 时</p>
<p>我们需要模拟整个 DOM 背景 UI时候的元素，可以通过 CSS 特性检测 <code>CSS @support</code> 进行控制：</p>
<p>核心 CSS 代码：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.bg</span> &#123;  </span><br><span class="line">    // 整个页面的 DOM 结构  </span><br><span class="line">&#125;  </span><br><span class="line">  </span><br><span class="line"><span class="selector-class">.g-glossy</span> &#123;  </span><br><span class="line">    <span class="attribute">position</span>: fixed;  </span><br><span class="line">    <span class="attribute">width</span>: <span class="number">600px</span>;  </span><br><span class="line">    <span class="attribute">height</span>: <span class="number">300px</span>;  </span><br><span class="line">    <span class="attribute">background-color</span>: <span class="built_in">rgba</span>(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0.5</span>);  </span><br><span class="line">    backdrop-<span class="attribute">filter</span>: <span class="built_in">blur</span>(<span class="number">10px</span>);  </span><br><span class="line">&#125;  </span><br><span class="line">  </span><br><span class="line"><span class="selector-class">.g-glossy-firefox</span> &#123;  </span><br><span class="line">    <span class="attribute">display</span>: none;  </span><br><span class="line">&#125;  </span><br><span class="line">  </span><br><span class="line"><span class="keyword">@supports</span> (<span class="attribute">background</span>: -moz-element(#bg)) &#123;  </span><br><span class="line">    <span class="selector-class">.g-glossy-firefox</span> &#123;  </span><br><span class="line">        <span class="attribute">display</span>: block;  </span><br><span class="line">        <span class="attribute">position</span>: fixed;  </span><br><span class="line">        <span class="attribute">width</span>: <span class="number">600px</span>;  </span><br><span class="line">        <span class="attribute">height</span>: <span class="number">300px</span>;  </span><br><span class="line">        <span class="attribute">background</span>: <span class="built_in">-moz-element</span>(#bg) no-repeat;  </span><br><span class="line">        <span class="attribute">filter</span>: <span class="built_in">blur</span>(<span class="number">10px</span>);  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;  </span><br></pre></td></tr></table></figure>

<p>简单解读一下：</p>
<ol>
<li>对于兼容 <code>backdrop-filter</code> 的，<code>.g-glossy</code> 内的代码将直接生效，并且 <code>.g-glossy-firefox</code> 不会展示</li>
<li>对于 Firefox 浏览器，因为 <code>backdrop-filter</code> 必然不兼容，所以 <code>.g-glossy</code> 内的 <code>backdrop-filter: blur(10px)</code> 不会生效，而 <code>@supports (background: -moz-element(#bg))</code> 内的样式会生效，此时 <code>.g-glossy-firefox</code> 将会利用 <code>background: -moz-element(#bg) no-repeat;</code> 模拟 id 为 <code>bg</code> 的元素</li>
</ol>
<p>当然，这里我们需要借助一定的 JavaScript 代码</p>
<p>计算我们的模拟页面 UI 的元素 <code>.g-glossy-firefox</code> 相对它模拟的 <code>#bg</code> 元素</p>
<p>也就是页面布局的一个定位偏差：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;  </span><br><span class="line">        <span class="keyword">let</span> blur = $(<span class="string">&#x27;.g-glossy-firefox&#x27;</span>)[<span class="number">0</span>].style;  </span><br><span class="line">        <span class="keyword">let</span> offset = $(<span class="string">&#x27;.g-glossy&#x27;</span>).eq(<span class="number">0</span>).offset();  </span><br><span class="line">  </span><br><span class="line">        <span class="function"><span class="keyword">function</span> <span class="title">updateBlur</span>(<span class="params"></span>) </span>&#123;  </span><br><span class="line">            blur.backgroundPosition =   </span><br><span class="line">                <span class="string">`<span class="subst">$&#123;-<span class="built_in">window</span>.scrollX - offset.left&#125;</span>px `</span> +   </span><br><span class="line">                <span class="string">`<span class="subst">$&#123;-<span class="built_in">window</span>.scrollY - offset.top&#125;</span>px`</span>;  </span><br><span class="line">        &#125;  </span><br><span class="line">        <span class="built_in">document</span>.addEventListener(<span class="string">&#x27;scroll&#x27;</span>, updateBlur, <span class="literal">false</span>), updateBlur();  </span><br><span class="line">&#125;);  </span><br></pre></td></tr></table></figure>

<p>OK，至此，我们就能完美的在 Firefox 上也实现毛玻璃的效果了：</p>
<p><img src="https://cdn.jsdelivr.net/gh/Vixcity/FigureBed/img/202109131446553.gif" alt="图片"></p>
<p>它相对于上面的第一种方案而言，最大的不同之处在于，它可以模拟各式各样的背景元素，背景元素可以不仅仅只是一张图片！它可以是各种复杂的结构！  </p>
<h2 id="总结一下"><a href="#总结一下" class="headerlink" title="总结一下"></a>总结一下</h2><p>简单对上述内容进行一个总结：</p>
<ul>
<li>你可以使用 <code>backdrop-filter</code> 对兼容它的浏览器非常简单的实现毛玻璃（磨砂玻璃）效果</li>
<li>对于不兼容 <code>backdrop-filter</code> 的浏览器，如果它只是简单背景，可以使用 <code>background-attachment: fixed</code> 配合 <code>filter: blur()</code> 进行模拟</li>
<li>对于 firefox 浏览器，你还可以使用 <code>moz-element()</code> 配合 <code>filter: blur()</code> 实现复杂背景毛玻璃效果</li>
<li>对于不兼容的上述 3 种效果的其他浏览器，设置了毛玻璃效果的元素，可以通过设置类似 <code>background: rgba(255, 255, 255, 0.5)</code> 的样式，使之回退到半透明效果，也算一种非常合理的降级效果，不会引起 Bug</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://vixcity.gitee.io/my-gitee-blog">Vixcity</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://vixcity.gitee.io/my-gitee-blog/2021/09/13/%E3%80%90CSS%E3%80%91%E5%85%A8%E5%85%BC%E5%AE%B9%E7%9A%84%E6%AF%9B%E7%8E%BB%E7%92%83%E6%95%88%E6%9E%9C/">http://vixcity.gitee.io/my-gitee-blog/2021/09/13/%E3%80%90CSS%E3%80%91%E5%85%A8%E5%85%BC%E5%AE%B9%E7%9A%84%E6%AF%9B%E7%8E%BB%E7%92%83%E6%95%88%E6%9E%9C/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://vixcity.gitee.io/my-gitee-blog" target="_blank">Vixcity</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/my-gitee-blog/tags/CSS/">CSS</a></div><div class="post_share"><div class="social-share" data-image="/my-gitee-blog/img/CSS.jpg" data-sites="wechat,qq"></div><link rel="stylesheet" href="/my-gitee-blog/" media="print" onload="this.media='all'"><script src="/my-gitee-blog/" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/my-gitee-blog/2021/09/14/%E3%80%90%E6%BA%90%E7%A0%81%E9%98%85%E8%AF%BB%E3%80%91%E6%89%8B%E6%91%B8%E6%89%8B%E6%95%99%E4%BD%A0%E8%B0%83%E8%AF%95%20vue-devtools%20%EF%BC%8C%E4%BD%A0%E7%A1%AE%E5%AE%9A%E4%B8%8D%E6%9D%A5%E7%9C%8B%E7%9C%8B%E5%98%9B/"><img class="prev-cover" src="/my-gitee-blog/img/vue%E7%9B%B8%E5%85%B3.jpg" onerror="onerror=null;src='/my-gitee-blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">【源码阅读】手摸手教你调试 vue-devtools ，你确定不来看看嘛</div></div></a></div><div class="next-post pull-right"><a href="/my-gitee-blog/2021/09/12/%E3%80%90%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E3%80%91%E5%85%B3%E4%BA%8E%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%9A%84%209%20%E5%A4%A7%E7%AD%96%E7%95%A5%E5%92%8C%206%20%E5%A4%A7%E6%8C%87%E6%A0%87/"><img class="next-cover" src="/my-gitee-blog/img/%E5%AE%87%E5%AE%99%E5%B2%A9%E7%9F%B3%E9%A3%9E%E8%88%B9%E5%A4%AA%E9%98%B3.jpg" onerror="onerror=null;src='/my-gitee-blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">【性能优化】关于性能优化的 9 大策略和 6 大指标</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/my-gitee-blog/2021/10/04/%E3%80%90CSS%E3%80%91CSS%20%E4%BB%A3%E7%A0%81%E9%87%8D%E6%9E%84%E4%B8%8E%E4%BC%98%E5%8C%96%E4%B9%8B%E8%B7%AF/" title="【CSS】CSS 代码重构与优化之路"><img class="cover" src="/my-gitee-blog/img/CSS.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-04</div><div class="title">【CSS】CSS 代码重构与优化之路</div></div></a></div><div><a href="/my-gitee-blog/2021/09/09/%E3%80%90CSS%E3%80%91margin%20%E5%A1%8C%E9%99%B7%E5%92%8C%E5%90%88%E5%B9%B6%E9%97%AE%E9%A2%98/" title="【CSS杂谈】margin 塌陷和合并问题"><img class="cover" src="/my-gitee-blog/img/CSS.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-09</div><div class="title">【CSS杂谈】margin 塌陷和合并问题</div></div></a></div><div><a href="/my-gitee-blog/2021/09/22/%E3%80%90CSS%E3%80%91%E5%AE%9E%E7%8E%B0%E6%96%B0%E6%8B%9F%E6%80%81(Neumorphism)%20UI%20%E9%A3%8E%E6%A0%BC/" title="【CSS】实现新拟态(Neumorphism) UI 风格"><img class="cover" src="/my-gitee-blog/img/CSS.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-22</div><div class="title">【CSS】实现新拟态(Neumorphism) UI 风格</div></div></a></div><div><a href="/my-gitee-blog/2021/10/11/%E3%80%90CSS%E3%80%9150%E4%B8%AA%E6%9C%89%E4%BB%B7%E5%80%BC%E7%9A%84CSS%E7%BC%96%E5%86%99%E8%A7%84%E5%88%99%EF%BC%8C%E8%AE%A9%E4%BD%A0%E5%86%99%E5%87%BA%E6%9B%B4%E5%A5%BD%E7%9A%84CSS/" title="【CSS】50个有价值的CSS编写规则，让你写出更好的CSS"><img class="cover" src="/my-gitee-blog/img/CSS.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-11</div><div class="title">【CSS】50个有价值的CSS编写规则，让你写出更好的CSS</div></div></a></div><div><a href="/my-gitee-blog/2021/09/16/%E3%80%90CSS%E3%80%91%E5%A6%99%E7%94%A8%20background%20%E5%AE%9E%E7%8E%B0%E8%8A%B1%E5%BC%8F%E6%96%87%E5%AD%97%E6%95%88%E6%9E%9C/" title="【CSS杂谈】妙用 background 实现花式文字效果"><img class="cover" src="/my-gitee-blog/img/CSS.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-16</div><div class="title">【CSS杂谈】妙用 background 实现花式文字效果</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="lv-container" data-id="city" data-uid="MTAyMC81NDQ0NS8zMDkxNg=="></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/my-gitee-blog/img/avatar.png" onerror="this.onerror=null;this.src='/my-gitee-blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Vixcity</div><div class="author-info__description">今日事，今日毕</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/my-gitee-blog/archives/"><div class="headline">文章</div><div class="length-num">55</div></a></div><div class="card-info-data-item is-center"><a href="/my-gitee-blog/tags/"><div class="headline">标签</div><div class="length-num">50</div></a></div><div class="card-info-data-item is-center"><a href="/my-gitee-blog/categories/"><div class="headline">分类</div><div class="length-num">18</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/Vixcity"><i class="fab fa-github"></i><span>我的Github</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/Vixcity" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:2091283625@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">这是Vixcity目前的小博客</div></div><div class="sticky_layout"><div class="card-widget card-history"><div class="card-content"><div class="item-headline"><i class="fas fa-clock fa-spin"></i><span>那年今日</span></div><div id="history-baidu" style="height: 100px;overflow: hidden;"><div class="history_swiper-container" id="history-container" style="width: 100%;height: 100%;"><div class="swiper-wrapper" id="history_container_wrapper" style="height:20px"></div></div></div></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/my-gitee-blog/2022/07/13/%E3%80%90NodeJS%E3%80%91NodeJS%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E8%AF%B7%E6%B1%82/" title="【NodeJS】NodeJS 服务端请求"><img src="/my-gitee-blog/img/NodeJs.jpg" onerror="this.onerror=null;this.src='/my-gitee-blog/img/404.jpg'" alt="【NodeJS】NodeJS 服务端请求"/></a><div class="content"><a class="title" href="/my-gitee-blog/2022/07/13/%E3%80%90NodeJS%E3%80%91NodeJS%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E8%AF%B7%E6%B1%82/" title="【NodeJS】NodeJS 服务端请求">【NodeJS】NodeJS 服务端请求</a><time datetime="2022-07-12T16:00:00.000Z" title="发表于 2022-07-13 00:00:00">2022-07-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/my-gitee-blog/2022/07/12/%E3%80%90Hexo%E3%80%91%E6%A0%87%E7%AD%BE%E6%A0%B7%E5%BC%8F%E5%88%97%E8%A1%A8%E5%8F%82%E8%80%83%20-%201/" title="【Hexo】标签样式列表参考 - 1"><img src="/my-gitee-blog/img/hexo.jpg" onerror="this.onerror=null;this.src='/my-gitee-blog/img/404.jpg'" alt="【Hexo】标签样式列表参考 - 1"/></a><div class="content"><a class="title" href="/my-gitee-blog/2022/07/12/%E3%80%90Hexo%E3%80%91%E6%A0%87%E7%AD%BE%E6%A0%B7%E5%BC%8F%E5%88%97%E8%A1%A8%E5%8F%82%E8%80%83%20-%201/" title="【Hexo】标签样式列表参考 - 1">【Hexo】标签样式列表参考 - 1</a><time datetime="2022-07-11T16:00:00.000Z" title="发表于 2022-07-12 00:00:00">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/my-gitee-blog/2022/07/12/%E3%80%90Hexo%E3%80%91%E6%A0%87%E7%AD%BE%E6%A0%B7%E5%BC%8F%E5%88%97%E8%A1%A8%E5%8F%82%E8%80%83%20-%202/" title="【Hexo】标签样式列表参考 - 2"><img src="/my-gitee-blog/img/hexo.jpg" onerror="this.onerror=null;this.src='/my-gitee-blog/img/404.jpg'" alt="【Hexo】标签样式列表参考 - 2"/></a><div class="content"><a class="title" href="/my-gitee-blog/2022/07/12/%E3%80%90Hexo%E3%80%91%E6%A0%87%E7%AD%BE%E6%A0%B7%E5%BC%8F%E5%88%97%E8%A1%A8%E5%8F%82%E8%80%83%20-%202/" title="【Hexo】标签样式列表参考 - 2">【Hexo】标签样式列表参考 - 2</a><time datetime="2022-07-11T16:00:00.000Z" title="发表于 2022-07-12 00:00:00">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/my-gitee-blog/2022/07/12/%E3%80%90Hexo%E3%80%91%E6%A0%87%E7%AD%BE%E6%A0%B7%E5%BC%8F%E5%88%97%E8%A1%A8%E5%8F%82%E8%80%83%20-%203/" title="【Hexo】标签样式列表参考 - 3"><img src="/my-gitee-blog/img/hexo.jpg" onerror="this.onerror=null;this.src='/my-gitee-blog/img/404.jpg'" alt="【Hexo】标签样式列表参考 - 3"/></a><div class="content"><a class="title" href="/my-gitee-blog/2022/07/12/%E3%80%90Hexo%E3%80%91%E6%A0%87%E7%AD%BE%E6%A0%B7%E5%BC%8F%E5%88%97%E8%A1%A8%E5%8F%82%E8%80%83%20-%203/" title="【Hexo】标签样式列表参考 - 3">【Hexo】标签样式列表参考 - 3</a><time datetime="2022-07-11T16:00:00.000Z" title="发表于 2022-07-12 00:00:00">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/my-gitee-blog/2022/07/07/%E3%80%90NodeJS%E3%80%91NodeJS%E5%85%A5%E9%97%A8%E5%AD%A6%E4%B9%A0/" title="【NodeJS】NodeJS入门学习"><img src="/my-gitee-blog/img/NodeJs.jpg" onerror="this.onerror=null;this.src='/my-gitee-blog/img/404.jpg'" alt="【NodeJS】NodeJS入门学习"/></a><div class="content"><a class="title" href="/my-gitee-blog/2022/07/07/%E3%80%90NodeJS%E3%80%91NodeJS%E5%85%A5%E9%97%A8%E5%AD%A6%E4%B9%A0/" title="【NodeJS】NodeJS入门学习">【NodeJS】NodeJS入门学习</a><time datetime="2022-07-06T16:00:00.000Z" title="发表于 2022-07-07 00:00:00">2022-07-07</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/my-gitee-blog/img/CSS.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By Vixcity</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div id="running-time"></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/my-gitee-blog/js/utils.js"></script><script src="/my-gitee-blog/js/main.js"></script><script src="/my-gitee-blog/js/tw_cn.js"></script><script src="/my-gitee-blog/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function loadLivere () {
  if (typeof LivereTower === 'object') {
    window.LivereTower.init()
  }
  else {
    (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
    })(document, 'script');
  }
}

if ('Livere' === 'Livere' || !false) {
  if (false) btf.loadComment(document.getElementById('lv-container'), loadLivere)
  else loadLivere()
}
else {
  function loadOtherComment () {
    loadLivere()
  }
}</script></div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/my-gitee-blog/js/newStyle.js"></script><script src="/my-gitee-blog/js/sakura.js"></script><script>setInterval(()=>{let create_time=Math.round(new Date("2021-9-8-00:00:00").getTime()/1000);let timestamp=Math.round((new Date().getTime()+8*60*60*1000)/1000);let second=timestamp-create_time;let time=new Array(0,0,0,0,0);if(second>=365*24*3600){time[0]=parseInt(second/(365*24*3600));second%=365*24*3600}if(second>=24*3600){time[1]=parseInt(second/(24*3600));second%=24*3600}if(second>=3600){time[2]=parseInt(second/3600);second%=3600}if(second>=60){time[3]=parseInt(second/60);second%=60}if(second>0){time[4]=second}currentTimeHtml='小博客已经安全运行 '+time[0]+' 年 '+time[1]+' 天 '+time[2]+' 时 '+time[3]+' 分 '+time[4]+' 秒';var elementById=document.getElementById('running-time');if(elementById){elementById.innerHTML=currentTimeHtml}},1000);</script><script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script><script src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-card-history/baiduhistory/js/main.js"></script><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>function electric_clock_injector_config(){
                var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
                var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img id="card-clock-loading" src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-clock/clock/images/weather/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading" class="entered loading"></div></div></div></div></div>';
                console.log('已挂载electric_clock')
                // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
            }if( document.getElementsByClassName('sticky_layout')[0] && (location.pathname ==='all'|| 'all' ==='all')){

            electric_clock_injector_config()
        } </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax  src="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.js"></script><div class="js-pjax"><script async="async">var arr = document.getElementsByClassName('recent-post-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '1s');
    arr[i].setAttribute('data-wow-delay', '0.5s');
    arr[i].setAttribute('data-wow-offset', '100');
    arr[i].setAttribute('data-wow-iteration', '1');
  }</script><script async="async">var arr = document.getElementsByClassName('card-widget');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script></div><script defer src="https://unpkg.zhimg.com/hexo-butterfly-wowjs/lib/wow.min.js"></script><script defer src="https://unpkg.zhimg.com/hexo-butterfly-wowjs/lib/wow_init.js"></script><!-- hexo injector body_end end --><script src="/my-gitee-blog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body></html>